#ifndef __OLLYLUA_SINGLETON_HPP__
#define __OLLYLUA_SINGLETON_HPP__
#include <boost/scoped_ptr.hpp>
#include <boost/thread/once.hpp>
#include <boost/noncopyable.hpp>
template <class T>
class Singleton : private boost::noncopyable
{
public:
	static T& GetInstance()
	{
		boost::call_once(init, flag_);
		return *self_;
	}
 	static T* GetInstancePtr()
 	{
 		boost::call_once(init, flag_);
 		return &*self_;
 	}
	static void init()
	{
		self_.reset(new T());
	}

protected:
	~Singleton() {}
	Singleton() {}

private:
	static boost::scoped_ptr <T> self_;
	static boost::once_flag flag_;
};
template <class T> boost::scoped_ptr<T> Singleton<T>::self_(0);
template <class T> boost::once_flag Singleton<T>::flag_ = BOOST_ONCE_INIT;
#endif//__OLLYLUA_SINGLETON_HPP__